#ifndef CONTROLLERSTATUS_H
#define CONTROLLERSTATUS_H

#include <QObject>
#include <QThread>
#include "serialport/controllerserialport.h"

class ControllerStatus : public QObject
{
    Q_OBJECT
    Q_PROPERTY(bool doorStatus READ doorStatus WRITE setDoorStatus NOTIFY doorStatusChanged)
    Q_PROPERTY(bool sWaterTankLow READ sWaterTankLow WRITE setSWaterTankLow NOTIFY sWaterTankLowChanged)
    Q_PROPERTY(bool sWaterTankHigh READ sWaterTankHigh WRITE setSWaterTankHigh NOTIFY sWaterTankHighChanged)
    Q_PROPERTY(bool bWaterTankLow READ bWaterTankLow WRITE setBWaterTankLow NOTIFY bWaterTankLowChanged)
    Q_PROPERTY(bool bWaterTankHigh READ bWaterTankHigh WRITE setBWaterTankHigh NOTIFY bWaterTankHighChanged)
    Q_PROPERTY(int bWaterTankTemp READ bWaterTankTemp WRITE setBWaterTankTemp NOTIFY bWaterTankTempChanged)
    Q_PROPERTY(int sWaterTankTemp READ sWaterTankTemp WRITE setSWaterTankTemp NOTIFY sWaterTankTempChanged)
    Q_PROPERTY(int pumpA READ pumpA WRITE setPumpA NOTIFY pumpAChanged)
    Q_PROPERTY(int pumpB READ pumpB WRITE setPumpB NOTIFY pumpBChanged)
    Q_PROPERTY(bool heaterA READ heaterA WRITE setHeaterA NOTIFY heaterAChanged)
    Q_PROPERTY(bool heaterB READ heaterB WRITE setHeaterB NOTIFY heaterBChanged)
    Q_PROPERTY(bool sHeater READ sHeater WRITE setSHeater NOTIFY sHeaterChanged)
    Q_PROPERTY(bool bHeaterA READ bHeaterA WRITE setBHeaterA NOTIFY bHeaterAChanged)
    Q_PROPERTY(bool bHeaterB READ bHeaterB WRITE setBHeaterB NOTIFY bHeaterBChanged)
    Q_PROPERTY(bool bWaterTankSwitch READ bWaterTankSwitch WRITE setBWaterTankSwitch NOTIFY bWaterTankSwitchChanged)
    Q_PROPERTY(bool sWaterTankSwitch READ sWaterTankSwitch WRITE setSWaterTankSwitch NOTIFY sWaterTankSwitchChanged)
    Q_PROPERTY(bool bInValve READ bInValve WRITE setBInValve NOTIFY bInValveChanged)
    Q_PROPERTY(bool sInValve READ sInValve WRITE setSInValve NOTIFY sInValveChanged)
    Q_PROPERTY(bool bOutValve READ bOutValve WRITE setBOutValve NOTIFY bOutValveChanged)
    Q_PROPERTY(bool doorSwitch READ doorSwitch WRITE setDoorSwitch NOTIFY doorSwitchChanged)
    Q_PROPERTY(bool annexA READ annexA WRITE setAnnexA NOTIFY annexAChanged)
    Q_PROPERTY(bool annexB READ annexB WRITE setAnnexB NOTIFY annexBChanged)
    Q_PROPERTY(int currentModeID READ currentModeID WRITE setCurrentModeID NOTIFY currentModeIDChanged)

public:
    explicit ControllerStatus(QObject *parent = nullptr);

    Q_INVOKABLE void openDoor();
    Q_INVOKABLE void closeDoor();
    Q_INVOKABLE void startTask(QByteArray task);

    //属性
    //门开关传感器
    bool doorStatus() { return m_doorStatus; }
    void setDoorStatus(bool doorStatus_);

    //小水箱高位传感器
    bool sWaterTankLow() { return m_sWaterTankLow; }
    void setSWaterTankLow(bool sWaterTankLow_);

    //小水箱高位传感器
    bool sWaterTankHigh() { return m_sWaterTankHigh; }
    void setSWaterTankHigh(bool sWaterTankHigh_);

    //大水箱低位传感器
    bool bWaterTankLow() { return m_bWaterTankLow; }
    void setBWaterTankLow(bool bWaterTankLow_);

    //大水箱高位传感器
    bool bWaterTankHigh() { return m_bWaterTankHigh; }
    void setBWaterTankHigh(bool bWaterTankHigh_);

    //大水箱温度
    int bWaterTankTemp() { return m_bWaterTankTemp; }
    void setBWaterTankTemp(int bWaterTankTemp_);

    //小水箱温度
    int sWaterTankTemp() { return m_sWaterTankTemp; }
    void setSWaterTankTemp(int sWaterTankTemp_);

    //添加液泵A档位
    int pumpA() { return m_pumpA; }
    void setPumpA(int pumpA_);

    //添加液泵B档位
    int pumpB() { return m_pumpB; }
    void setPumpB(int pumpB_);

    //烘干加热棒1
    bool heaterA() { return m_heaterA; }
    void setHeaterA(bool heaterA_);

    //烘干加热棒2
    bool heaterB() { return m_heaterB; }
    void setHeaterB(bool heaterB_);

    //小水箱加热棒
    bool sHeater() { return m_sHeater; }
    void setSHeater(bool sHeater_);

    //大水箱加热棒1
    bool bHeaterA() { return m_bHeaterA; }
    void setBHeaterA(bool bHeaterA_);

    //大水箱加热棒2
    bool bHeaterB() { return m_bHeaterB; }
    void setBHeaterB(bool bHeaterB_);

    //大水箱水泵开关
    bool bWaterTankSwitch() { return m_bWaterTankSwitch; }
    void setBWaterTankSwitch(bool bWaterTankSwitch_);

    //小水箱水泵开关
    bool sWaterTankSwitch() { return m_sWaterTankSwitch; }
    void setSWaterTankSwitch(bool sWaterTankSwitch_);

    //小水箱进水阀门
    bool bInValve() { return m_bInValve; }
    void setBInValve(bool bInValve_);

    //大水箱进水阀门
    bool sInValve() { return m_sInValve; }
    void setSInValve(bool sInValve_);

    //大水箱排水阀门
    bool bOutValve() { return m_bOutValve; }
    void setBOutValve(bool bOutValve_);

    //门锁开关
    bool doorSwitch() { return m_doorSwitch; }
    void setDoorSwitch(bool doorSwitch_);

    //添加液量A
    bool annexA() { return m_annexA; }
    void setAnnexA(bool annexA_);

    //添加液量B
    bool annexB() { return m_annexB; }
    void setAnnexB(bool annexB_);

    //当前选择模式的ID
    int currentModeID() { return m_currentModeID; }
    void setCurrentModeID(int currentModeID_);

signals:

    void doorStatusChanged(bool doorStatus_);   //门开关传感器
    void sWaterTankLowChanged(bool sWaterTankLow_); //小水箱高位传感器
    void sWaterTankHighChanged(bool sWaterTankHigh_);   //小水箱低位传感器
    void bWaterTankLowChanged(bool bWaterTankLow_);     //大水箱高位传感器
    void bWaterTankHighChanged(bool bWaterTankHigh_);   //大水箱地位传感器
    void bWaterTankTempChanged(int bWaterTankTemp_);    //大水箱温度
    void sWaterTankTempChanged(int sWaterTankTemp_);    //小水箱温度
    void pumpAChanged(int pumpA_);  //添加液泵A档位
    void pumpBChanged(int pumpB_);  //添加液泵B档位
    void heaterAChanged(bool heaterA_); //烘干加热棒1
    void heaterBChanged(bool heaterB_); //烘干加热棒2
    void sHeaterChanged(bool sHeater_); //小水箱加热棒
    void bHeaterAChanged(bool bHeaterA_);   //大水箱加热棒1
    void bHeaterBChanged(bool bHeaterB_);   //大水箱加热棒2
    void bWaterTankSwitchChanged(bool bWaterTankSwitch_);   //大水箱水泵开关
    void sWaterTankSwitchChanged(bool sWaterTankSwitch_);   //小水箱水泵开关
    void bInValveChanged(bool bInValve_);   //大水箱进水阀门
    void sInValveChanged(bool sInValve_);   //小水箱进水阀门
    void bOutValveChanged(bool bOutValve_); //大水箱排水阀门
    void doorSwitchChanged(bool doorSwitch_);   //门锁开关
    void annexAChanged(bool annexA_);
    void annexBChanged(bool annexB_);
    void currentModeIDChanged(int id);

    void openDoorSignal();
    void closeDoorSignal();

public slots:

private:
    QByteArray HexStringToByteArray(QString HexString);
    QString ByteArrayToHexString(QByteArray data);

private slots:
    void analyzeData(QByteArray data);

private:
    ControllerSerialPort *serialPort;
    QThread *serialThread;

    //属性
    bool m_doorStatus;  //门开关传感器
    bool m_sWaterTankLow;   //小水箱高位传感器
    bool m_sWaterTankHigh;  //小水箱低位传感器
    bool m_bWaterTankLow;   //大水箱高位传感器
    bool m_bWaterTankHigh;  //大水箱地位传感器

    int m_bWaterTankTemp;   //大水箱温度
    int m_sWaterTankTemp;   //小水箱温度

    int m_pumpA;    //添加液泵A档位
    int m_pumpB;    //添加液泵B档位
    bool m_heaterA; //烘干加热棒1
    bool m_heaterB; //烘干加热棒2
    bool m_sHeater; //小水箱加热棒
    bool m_bHeaterA;    //大水箱加热棒1
    bool m_bHeaterB;    //大水箱加热棒2

    bool m_bWaterTankSwitch;    //大水箱水泵开关
    bool m_sWaterTankSwitch;    //小水箱水泵开关
    bool m_bInValve;    //大水箱进水阀门
    bool m_sInValve;    //小水箱进水阀门
    bool m_bOutValve;   //大水箱排水阀门
    bool m_doorSwitch;  //门锁开关

    bool m_annexA;
    bool m_annexB;

    int m_currentModeID;
};

#endif // CONTROLLERSTATUS_H
